Page({
  data:{
    contentId:0,
    userbookId:0,
    allqidList:[],
    allquestionList:[],
    questionList:[],
    key: '',
    bookPage: 0,
    priorPage: 0,
    page: 0,
    scrollId:'',
    scrollleft:false,
    scrollright:false,
    showAll:false
  },
  onLoad:function(options) {
    let qlist = wx.getStorageSync('qlist'+options.contentId);
    let allqlist = [];
    let allqidList = [];
    qlist.forEach((item)=>{
      allqlist.push(item.url);
      allqidList.push(item.id);
    })
    this.setData({
      contentId:options.contentId,
      userbookId:options.userbookId,
      key:options.key,
      bookPage:parseInt(options.page),
      page:0,
      allqidList:allqidList,
      allquestionList:allqlist,
      questionList:[allqlist[0],allqlist[1]]
    })
  },
  pagingU() {
    if (this.data.scrollright==true) {
      if (this.data.page==1&&this.data.priorPage<this.data.page) {
        this.setData({
          questionList: [this.data.allquestionList[0],this.data.allquestionList[1]],
          priorPage:0,
          page:0
        })
      }else {
        this.setData({
          priorPage:this.data.page,
          page:this.data.page-1
        })
      }
    }else if (this.data.page==1) {
      this.setData({
        priorPage:2,
        page:1
      })
    }
    this.setData({
      showAll:false,
      scrollleft:true,
      scrollright:false
    })
    if(this.data.scrollleft==true&&this.data.page>=1&&this.data.priorPage>=this.data.page) {
      let curPage = this.data.page;
      if (this.data.allquestionList[curPage-2]==undefined) {
        this.setData({
          questionList: [this.data.allquestionList[curPage-1],this.data.allquestionList[curPage]],
          scrollId: 'q1',
          priorPage:curPage,
          page:curPage-1
        })
      }else {
        this.setData({
          questionList: [this.data.allquestionList[curPage-1],this.data.allquestionList[curPage],this.data.allquestionList[curPage+1]],
          scrollId: 'q1',
          priorPage:curPage,
          page:curPage-1
        })
      }
    }
  },
  pagingD() {
    if (this.data.scrollleft==true) {
      if (this.data.page>0) {
        this.setData({
          priorPage:this.data.page,
          page:this.data.page+1
        })
      }else {
        this.setData({
          priorPage:0,
          page:0
        })
      }
    }
    this.setData({
      showAll:false,
      scrollleft:false,
      scrollright:true
    })
    if(this.data.scrollright==true&&this.data.page>=0&&this.data.page<=this.data.allquestionList.length-2&&this.data.priorPage<=this.data.page) {
      let curPage = this.data.page;
      if (this.data.allquestionList[curPage+2]==undefined) {
        this.setData({
          questionList: [this.data.allquestionList[curPage],this.data.allquestionList[curPage+1]],
          scrollId: 'q1',
          priorPage:curPage,
          page:curPage+1
        })
      }else {
        this.setData({
          questionList: [this.data.allquestionList[curPage],this.data.allquestionList[curPage+1],this.data.allquestionList[curPage+2]],
          scrollId: 'q1',
          priorPage:curPage,
          page:curPage+1
        })
      }
    }
  },
  getPhone:function() {
    wx.navigateTo({
      url: '../head/head?userbookId='+this.data.userbookId+
        '&contentId='+this.data.contentId+
        '&key='+this.data.key+
        '&page='+this.data.bookPage+
        '&qid='+this.data.allqidList[this.data.page]+
        '&qpage='+this.data.page
    });
  }
})